package algorithmTopics.matrix;

import java.util.Scanner;

public class oda002 {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();
        String b = sc.nextLine();
        sc.close();
        System.out.println(maxSubstring(a,b));
    }

    static String maxSubstring(String a, String b){
        int lenA = a.length();
        int lenB = b.length();
        // dp[i][j],a字符串i下标处结尾，b字符串j下标处结尾的之前最大公共长度
        int[][] dp = new int[lenA + 1][lenB + 1];
        int maxLen = 0;
        String res = "";
        //遍历俩个字符串
        for (int i = 1; i <= lenA; i++) {
            for (int j = 1; j <= lenB; j++) {
                // 只有两个相等的时候才会 + 1
                if(a.charAt(i- 1) == b.charAt(j - 1)){
                    //转移方程
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    //实时判断即可
                    if(dp[i][j] > maxLen){
                        maxLen = dp[i][j];
                        res = a.substring(i - maxLen,i);
                    }
                }
            }
        }

        return res;

    }

}
